package net.kleinhenz.questor.game;

import java.util.HashMap;
import java.util.Map;

import net.kleinhenz.questor.game.rules.simple.SimpleV1Rules;

public class RulesFactory {
	
	@SuppressWarnings("rawtypes")
	private static final Map<String, Class> rulesMap = new HashMap<String, Class>();
    static {
    	// declare new rule system keys here
    	rulesMap.put("simpleV1", SimpleV1Rules.class);
    }
    
    public static Rules getRules(String rulesType) {
    	if (rulesMap.containsKey(rulesType))
			try {
				return (Rules)rulesMap.get(rulesType).newInstance();
			} catch (InstantiationException e) {
	    		throw new RuntimeException("Error creating rules type " + rulesType + ":" + e.getMessage());
			} catch (IllegalAccessException e) {
	    		throw new RuntimeException("Error accessing rules type " + rulesType + ":" + e.getMessage());
			}
		else
    		throw new RuntimeException("Rules type " + rulesType + " unknown.");
    }	
}
